<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学号" prop="studentId">
        <el-input
            v-model="queryParams.studentId"
            placeholder="请输入学号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="studentName">
        <el-input
            v-model="queryParams.studentName"
            placeholder="请输入姓名"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="studentCnum">
        <el-input
            v-model="queryParams.studentCnum"
            placeholder="请输入证件号码"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="studentSex" label-width="100px">
        <el-select v-model="queryParams.studentSex" placeholder="请选择性别" filterable>
          <el-option
              v-for="dict in sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="籍贯" prop="studentJiguan">
        <el-input
            v-model="queryParams.studentJiguan"
            placeholder="请输入籍贯"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生地" prop="studentBire">
        <el-input
            v-model="queryParams.studentBire"
            placeholder="请输入出生地"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生源地" prop="studentStre">
        <el-input
            v-model="queryParams.studentStre"
            placeholder="请输入生源地"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户口所在地" prop="studentHk">
        <el-input
            v-model="queryParams.studentHk"
            placeholder="请输入户口所在地"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="studentHkxxdz">
        <el-input
            v-model="queryParams.studentHkxxdz"
            placeholder="请输入户口所在地详细地址"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="院系" prop="studentYx">
        <el-select v-model="queryParams.studentYx" placeholder="请选择院系" filterable
                   @change="handleCollegeChange"  style="width: 200px;">
          <el-option v-for="item in yxList"
                     :key="item.collegeId"
                     :label="item.collegeName"
                     :value="item.collegeCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="专业" prop="studentZy">
        <el-select
            v-model="queryParams.studentZy"
            placeholder="请选择专业"
            filterable
            :disabled="!queryParams.studentYx"
            style="width: 200px;"
        >
          <el-option v-for="item in zyList"
                     :key="item.id"
                     :label="item.majorName"
                     :value="item.majorCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="研究方向" prop="studentYjfxm">
        <el-input
            v-model="queryParams.studentYjfxm"
            placeholder="请输入研究方向代码"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="研究方向" prop="studentYjfx">
        <el-input
            v-model="queryParams.studentYjfx"
            placeholder="请输入研究方向"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培养层次" prop="studentPycc">
        <el-input
            v-model="queryParams.studentPycc"
            placeholder="请输入培养层次"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生类别" prop="studentLb">
        <el-input
            v-model="queryParams.studentLb"
            placeholder="请输入学生类别"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年级" prop="studentNj">
        <el-select v-model="queryParams.studentNj" placeholder="请选择年级" filterable style="width: 200px;">
          <el-option
              v-for="dict in grade"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="校区" prop="studentXq">
        <el-select v-model="queryParams.studentXq" placeholder="请选择校区" filterable style="width: 200px;">
          <el-option
              v-for="dict in campus_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="导师" prop="studentDs">
        <el-select v-model="queryParams.studentDs" placeholder="请选择导师" filterable clearable
                   @keyup.enter="handleQuery" style="width: 200px;">
          <el-option v-for="item in teacherList"
                     :key="item.id"
                     :label="item.name"
                     :value="item.teacherCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="导师2" prop="studentDs2">
        <el-select v-model="queryParams.studentDs2" placeholder="请选择导师2" filterable clearable
                   @keyup.enter="handleQuery" style="width: 200px;">
          <el-option v-for="item in teacherList"
                     :key="item.id"
                     :label="item.name"
                     :value="item.teacherCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="studentBj">
        <el-input
            v-model="queryParams.studentBj"
            placeholder="请输入班级"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学制" prop="studentXz">
        <el-select v-model="queryParams.studentXz" placeholder="请选择学制" filterable style="width: 200px;">
          <el-option
              v-for="dict in xuezhi"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入学季节" prop="studentRxjj">
        <el-select v-model="queryParams.studentRxjj" placeholder="请选择入学季节" filterable style="width: 200px;">
          <el-option
              v-for="dict in semester"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入学年月" prop="studentRxny">
        <el-date-picker clearable
                        v-model="queryParams.studentRxny"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择入学年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="培养方式" prop="studentPyfs">
        <el-input
            v-model="queryParams.studentPyfs"
            placeholder="请输入培养方式"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入学方式" prop="studentRxf">
        <el-input
            v-model="queryParams.studentRxf"
            placeholder="请输入入学方式"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报道状态" prop="studentStatus">
        <el-select v-model="queryParams.studentStatus" placeholder="请选择报道状态" filterable style="width: 200px;">
          <el-option
              v-for="dict in bdzt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['student:studentManger:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['student:studentManger:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['student:studentManger:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            @click="handleDeleteAll"
            v-hasPermi="['student:studentManger:remove']"
        >删除所有信息</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['student:studentManger:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentMangerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="60" align="center" />
      <el-table-column label="学生毕业照片" align="center" prop="studentGphoto" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.studentGphoto" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="学生照片" align="center" prop="studentPhoto" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.studentPhoto" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="学号" align="center" prop="studentId" />
      <el-table-column label="姓名" align="center" prop="studentName" />
      <el-table-column label="学生性别" align="center" prop="studentSex" >
        <template #default="scope">
          {{ sys_user_sex.find(item => item.value === scope.row.studentSex)?.label || '无' }}
        </template>
      </el-table-column>
      <el-table-column label="院系" align="center">
        <template #default="scope">
          {{ yxList.find(item => item.collegeCode === scope.row.studentYx)?.collegeName || '无' }}
        </template>
      </el-table-column>
      <el-table-column label="专业" align="center">
        <template #default="scope">
          {{ zyZlist.find(item => item.majorCode === scope.row.studentZy)?.majorName || '无' }}
        </template>
      </el-table-column>
      <el-table-column label="研究方向" align="center" prop="studentYjfx" />
      <el-table-column label="培养层次" align="center" prop="studentPycc" />
      <el-table-column label="学生类别" align="center" prop="studentLb" />
      <el-table-column label="学制" align="center">
        <template #default="scope">
          {{ xuezhi.find(item => item.value === scope.row.studentXz)?.label || '无' }}
        </template>
      </el-table-column>
      <el-table-column label="入学季节" align="center">
        <template #default="scope">
          {{ semester.find(item => item.value === scope.row.studentRxjj)?.label || '无' }}
        </template>
      </el-table-column>
      <el-table-column label="查看详情" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleDetail(scope.row)" v-hasPermi="['student:studentManger:edit']">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['student:studentManger:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['student:studentManger:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改学生信息管理对话框 -->
    <el-dialog :title="title" v-model="open" width="1500px" append-to-body class="student-detail-dialog">
      <el-form ref="studentMangerRef" :model="form" :rules="rules" label-width="170px">
        <el-row :gutter="20">
          <el-col :span="16">
            <!-- 基本信息卡片 -->
            <el-card shadow="hover" class="info-card">
              <template #header>
                <div class="card-header">
                  <span>基本信息</span>
                </div>
              </template>
              <el-row :gutter="20">
                <el-col :span="12">
                  <div class="info-group">
                    <h4 class="group-title">身份信息</h4>
                    <el-form-item label="学号" prop="studentId">
                      <el-input v-model="form.studentId" placeholder="请输入学号" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="姓名" prop="studentName" @input="getNamePy">
                      <el-input v-model="form.studentName" placeholder="请输入姓名" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="性别" prop="studentSex">
                      <el-select v-model="form.studentSex" placeholder="请选择性别" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_user_sex"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="姓名拼音" prop="namePy">
                      <el-input v-model="form.namePy" placeholder="请输入姓名拼音" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="曾用名" prop="studentNames">
                      <el-input v-model="form.studentNames" placeholder="请输入曾用名" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="出生日期" prop="birthday">
                      <el-date-picker clearable
                                      v-model="form.birthday"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择出生日期"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="民族" prop="studentNation">
                      <el-select v-model="form.studentNation" placeholder="请选择民族" filterable :disabled="isDetail">
                        <el-option v-for="item in originnationlist"
                                   :key="item.id"
                                   :label="item.nadictLabel"
                                   :value="item.nadictValue">
                        </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="政治面貌" prop="studentPa">
                      <el-select v-model="form.studentPa" placeholder="请选择政治面貌" filterable :disabled="isDetail">
                        <el-option v-for="item in originpaList"
                                   :key="item.id"
                                   :label="item.politicalLabel"
                                   :value="item.politicalValue">
                        </el-option>
                      </el-select>
                    </el-form-item>
                    <!-- 新增：现役军人码字段 -->
                    <el-form-item label="现役军人码" prop="studentXyjrDm">
                      <el-input v-model="form.studentXyjrDm" placeholder="请输入现役军人码" :disabled="isDetail" />
                    </el-form-item>
                  </div>
                </el-col>

                <el-col :span="12">
                  <div class="info-group">
                    <h4 class="group-title">证件信息</h4>
                    <el-form-item label="入党时间" prop="studentTjp">
                      <el-date-picker clearable
                                      v-model="form.studentTjp"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择入党时间"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="证件类型" prop="studentCtype">
                      <el-select v-model="form.studentCtype" placeholder="请选择证件类型" filterable :disabled="isDetail">
                        <el-option v-for="item in idcardList"
                                   :key="item.id"
                                   :label="item.cardtLabel"
                                   :value="item.cardtValue">
                        </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="证件号码" prop="studentCnum">
                      <el-input v-model="form.studentCnum" placeholder="请输入证件号码" @input="getSex" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="宗教信仰" prop="studentRe">
                      <el-input v-model="form.studentRe" placeholder="请输入宗教信仰" :disabled="isDetail" />
                    </el-form-item>
                    <!-- 补充：是否本校推免 -->
                    <el-form-item label="是否本校推免" prop="studentSfbxtm">
                      <el-select v-model="form.studentSfbxtm" placeholder="请选择是否本校推免" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_yes_no"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>

                  <div class="info-group">
                    <h4 class="group-title">地区信息</h4>
                    <el-form-item label="国家地区" prop="studentRegion">
                      <el-cascader
                          v-model="selectedOptions"
                          style="width: 100%;"
                          size="large"
                          :options="options"
                          @change="handleChange"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="籍贯" prop="studentJiguan">
                      <el-cascader
                          v-model="selectedJiguan"
                          style="width: 100%;"
                          size="large"
                          :options="options"
                          @change="handleChangeJiguan"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="出生地" prop="studentBire">
                      <el-cascader
                          v-model="selectedBire"
                          style="width: 100%;"
                          size="large"
                          :options="options"
                          @change="handleChangeBire"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="生源地" prop="studentStre">
                      <el-cascader
                          v-model="selectedStre"
                          style="width: 100%;"
                          size="large"
                          :options="options"
                          @change="handleChangeStre"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="户口所在地" prop="studentHk">
                      <el-cascader
                          v-model="selectedHk"
                          style="width: 100%;"
                          size="large"
                          :options="options"
                          @change="handleChangeHk"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="详细地址" prop="studentHkxxdz">
                      <el-input v-model="form.studentHkxxdz" placeholder="请输入详细地址" :disabled="isDetail" />
                    </el-form-item>
                    <el-form-item label="招生单位所在省市码" prop="studentZsdwSssm">
                      <el-cascader
                          v-model="selectedSs"
                          style="width: 100%;"
                          size="large"
                          :options="optionsa"
                          @change="handleChangeSs"
                          :disabled="isDetail">
                      </el-cascader>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>

              <div class="info-group">
                <h4 class="group-title">其他信息</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="港澳台侨" prop="gangaotaiqiao">
                      <el-select v-model="form.gangaotaiqiao" placeholder="请选择港澳台侨类别" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in originpadict"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="婚姻状况" prop="studentMarr">
                      <el-select v-model="form.studentMarr" placeholder="请选择婚姻状况" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in marital_status"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="健康状况" prop="studentHe">
                      <el-input v-model="form.studentHe" placeholder="请输入健康状况" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="病史" prop="studentBs">
                      <el-input v-model="form.studentBs" placeholder="请输入病史" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-card>

            <!-- 联系方式卡片 -->
            <el-card shadow="hover" class="info-card">
              <template #header>
                <div class="card-header">
                  <span>联系方式</span>
                </div>
              </template>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="银行卡号" prop="studentYhkh">
                    <el-input v-model="form.studentYhkh" placeholder="请输入银行卡号" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="银行卡姓名" prop="studentYhkname">
                    <el-input v-model="form.studentYhkname" placeholder="请输入银行卡姓名" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="火车起点站" prop="studentTrains">
                    <el-input v-model="form.studentTrains" placeholder="请输入火车起点站" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="火车终点站" prop="studentTraine">
                    <el-input v-model="form.studentTraine" placeholder="请输入火车终点站" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="问题学生类别" prop="studentQues">
                    <el-input v-model="form.studentQues" placeholder="请输入问题学生类别" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="生源地社区第一书记" prop="studentShuji" label-width="140px">
                    <el-input v-model="form.studentShuji" placeholder="请输入生源地社区第一书记" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="第一书记联系电话" prop="studentSjnum" label-width="140px">
                    <el-input v-model="form.studentSjnum" placeholder="请输入第一书记联系电话" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="辅导员" prop="studentFdy">
                    <el-select v-model="form.studentFdy" placeholder="请选择辅导员" filterable :disabled="isDetail">
                      <el-option
                          v-for="item in teacherList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.name">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="辅导员联系电话" prop="studentFdynum">
                    <el-input v-model="form.studentFdynum" placeholder="请输入辅导员联系电话" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <!-- 补充：本人手机号 -->
                <el-col :span="12">
                  <el-form-item label="本人手机号" prop="studentSjh">
                    <el-input v-model="form.studentSjh" placeholder="请输入本人手机号" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="事由" prop="studentSy">
                    <el-input v-model="form.studentSy" placeholder="请输入事由" :disabled="isDetail" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>

            <!-- 教育背景卡片 -->
            <el-card shadow="hover" class="info-card">
              <template #header>
                <div class="card-header">
                  <span>教育背景</span>
                </div>
              </template>

              <div class="info-group">
                <h4 class="group-title">学习信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="院系" prop="studentYx">
                      <el-select v-model="form.studentYx" placeholder="请选择院系" @change="handleCollegeChange" filterable :disabled="isDetail">
                        <el-option v-for="item in yxList"
                                   :key="item.collegeId"
                                   :label="item.collegeName"
                                   :value="item.collegeCode">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="专业" prop="studentZy">
                      <el-select
                          v-model="form.studentZy"
                          placeholder="请选择专业"
                          filterable
                          :disabled="!form.studentYx || isDetail">
                        <el-option v-for="item in zyList"
                                   :key="item.id"
                                   :label="item.majorName"
                                   :value="item.majorCode">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="研究方向" prop="studentYjfx">
                      <el-input v-model="form.studentYjfx" placeholder="请输入研究方向" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="培养层次" prop="studentPycc">
                      <el-select v-model="form.studentPycc" placeholder="请选择培养层次" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in culture_program_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="学生类别" prop="studentLb">
                      <el-input v-model="form.studentLb" placeholder="请输入学生类别" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="年级" prop="studentNj">
                      <el-select v-model="form.studentNj" placeholder="请选择年级" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in grade"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="校区" prop="studentXq">
                      <el-select v-model="form.studentXq" placeholder="请选择校区" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in campus_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="班级" prop="studentBj">
                      <el-input v-model="form.studentBj" placeholder="请输入班级" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">导师信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="导师编号" prop="studentDsbh">
                      <el-input v-model="form.studentDsbh" placeholder="请输入导师编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="导师" prop="studentDs">
                      <el-select v-model="form.studentDs" placeholder="请选择导师" filterable :disabled="isDetail">
                        <el-option v-for="item in teacherList"
                                   :key="item.id"
                                   :label="item.name"
                                   :value="item.teacherCode">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="导师2" prop="studentDs2">
                      <el-select v-model="form.studentDs2" placeholder="请选择导师2" filterable :disabled="isDetail">
                        <el-option v-for="item in teacherList"
                                   :key="item.id"
                                   :label="item.name"
                                   :value="item.teacherCode">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <!-- 新增：导师1编号 -->
                  <el-col :span="12">
                    <el-form-item label="导师1编号" prop="studentDsbh">
                      <el-input v-model="form.studentDsbh" placeholder="请输入导师1编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <!-- 新增：导师2编号 -->
                  <el-col :span="12">
                    <el-form-item label="导师2编号" prop="studentDs2bh">
                      <el-input v-model="form.studentDs2bh" placeholder="请输入导师2编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">学制与入学信息</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="学制" prop="studentXz">
                      <el-select v-model="form.studentXz" placeholder="请选择学制" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in xuezhi"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="入学季节" prop="studentRxjj">
                      <el-select v-model="form.studentRxjj" placeholder="请选择入学季节" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in semester"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="入学年月" prop="studentRxny">
                      <el-date-picker clearable
                                      v-model="form.studentRxny"
                                      type="month"
                                      value-format="YYYY-MM"
                                      placeholder="请选择入学年月"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="预计毕业时间" prop="studentYjby">
                      <el-date-picker clearable
                                      v-model="form.studentYjby"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择预计毕业时间"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="实际毕业时间" prop="studentSjby">
                      <el-date-picker clearable
                                      v-model="form.studentSjby"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择实际毕业时间"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="门类" prop="studentMl">
                      <el-input v-model="form.studentMl" placeholder="请输入门类" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="培养方式" prop="studentPyfs">
                      <el-input v-model="form.studentPyfs" placeholder="请输入培养方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="入学方式" prop="studentRxf">
                      <el-input v-model="form.studentRxf" placeholder="请输入入学方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <!-- 补充：培养方案ID -->
                  <el-col :span="12">
                    <el-form-item label="培养方案ID" prop="trainingProgramId">
                      <el-input v-model="form.trainingProgramId" placeholder="请输入培养方案ID" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="在校生注册学号" prop="studentZxszcXh">
                      <el-input v-model="form.studentZxszcXh" placeholder="请输入在校生注册学号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="考生来源码" prop="studentKslyDm">
                      <el-input v-model="form.studentKslyDm" placeholder="请输入考生来源码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="录取类别码" prop="studentLqlbDm">
                      <el-input v-model="form.studentLqlbDm" placeholder="请输入录取类别码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="考试方式码" prop="studentKsfsDm">
                      <el-input v-model="form.studentKsfsDm" placeholder="请输入考试方式码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">学习方式与计划</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="专项计划" prop="studentZxjh">
                      <el-input v-model="form.studentZxjh" placeholder="请输入专项计划" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="专项计划2" prop="studentZxjh2">
                      <el-input v-model="form.studentZxjh2" placeholder="请输入专项计划2" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="就读方式" prop="studentJdfs">
                      <el-input v-model="form.studentJdfs" placeholder="请输入就读方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="学习方式" prop="studentXxfs">
                      <el-input v-model="form.studentXxfs" placeholder="请输入学习方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="进修性质" prop="studentJxxz">
                      <el-input v-model="form.studentJxxz" placeholder="请输入进修性质" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="是否本校定向" prop="studentSfbxdx">
                      <el-select v-model="form.studentSfbxdx" placeholder="请选择是否本校定向" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_yes_no"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="是否跨学科" prop="studentSflkxk">
                      <el-select v-model="form.studentSflkxk" placeholder="请选择是否跨学科" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_yes_no"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">学生类型与身份</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="是否在职生" prop="studentSfzzs">
                      <el-select v-model="form.studentSfzzs" placeholder="请选择是否在职生" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_yes_no"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="是否留学生" prop="studentSflxs">
                      <el-select v-model="form.studentSflxs" placeholder="请选择是否留学生" filterable :disabled="isDetail">
                        <el-option
                            v-for="dict in sys_yes_no"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="特殊学生类型" prop="studentTsxsx">
                      <el-input v-model="form.studentTsxsx" placeholder="请输入特殊学生类型" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="学生分类" prop="studentXsfl">
                      <el-input v-model="form.studentXsfl" placeholder="请输入学生分类" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="学位类型" prop="studentXwlx">
                      <el-input v-model="form.studentXwlx" placeholder="请输入学位类型" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="学位" prop="studentXw">
                      <el-input v-model="form.studentXw" placeholder="请输入学位" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">毕业与答辩信息</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="答辩时间" prop="studentDbsj">
                      <el-date-picker clearable
                                      v-model="form.studentDbsj"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择答辩时间"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="毕业证号" prop="studentByzh">
                      <el-input v-model="form.studentByzh" placeholder="请输入毕业证号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="学位证号" prop="studentXwzh">
                      <el-input v-model="form.studentXwzh" placeholder="请输入学位证号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="档案去向与内容" prop="studentDaqx">
                      <el-input v-model="form.studentDaqx" type="textarea" placeholder="请输入档案去向与内容" rows="3" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="奖惩信息" prop="studentJcxx">
                      <el-input v-model="form.studentJcxx" type="textarea" placeholder="请输入奖惩信息" rows="3" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <!-- 新增硕士学位相关字段 -->
                  <el-col :span="8">
                    <el-form-item label="获硕士学位的单位代码" prop="studentSxwdywDm">
                      <el-input v-model="form.studentSxwdywDm" placeholder="请输入获硕士学位的单位代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="获硕士学位的单位名称" prop="studentSxwdywMc">
                      <el-input v-model="form.studentSxwdywMc" placeholder="请输入获硕士学位的单位名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="获硕士学位专业代码" prop="studentSxwzyDm">
                      <el-input v-model="form.studentSxwzyDm" placeholder="请输入获硕士学位专业代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="获硕士学位专业名称" prop="studentSxwzyMc">
                      <el-input v-model="form.studentSxwzyMc" placeholder="请输入获硕士学位专业名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="获硕士学位年月" prop="studentSxwyxny">
                      <el-date-picker clearable
                                      v-model="form.studentSxwyxny"
                                      type="month"
                                      value-format="YYYY-MM"
                                      placeholder="请选择获硕士学位年月"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士学位证书编号" prop="studentSxwzh">
                      <el-input v-model="form.studentSxwzh" placeholder="请输入硕士学位证书编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="获硕士学位方式" prop="studentSxwfs">
                      <el-input v-model="form.studentSxwfs" placeholder="请输入获硕士学位方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <!-- 新增硕士毕业及最后学位学历码字段 -->
                  <el-col :span="8">
                    <el-form-item label="硕士毕业单位代码" prop="studentSbbydwDm">
                      <el-input v-model="form.studentSbbydwDm" placeholder="请输入硕士毕业单位代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士毕业单位" prop="studentSbbydwMc">
                      <el-input v-model="form.studentSbbydwMc" placeholder="请输入硕士毕业单位" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士毕业专业代码" prop="studentSbbyzyDm">
                      <el-input v-model="form.studentSbbyzyDm" placeholder="请输入硕士毕业专业代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士毕业专业名称" prop="studentSbbyzyMc">
                      <el-input v-model="form.studentSbbyzyMc" placeholder="请输入硕士毕业专业名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士毕业年月" prop="studentSbbyny">
                      <el-date-picker clearable
                                      v-model="form.studentSbbyny"
                                      type="month"
                                      value-format="YYYY-MM"
                                      placeholder="请选择硕士毕业年月"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="硕士毕业证书编号" prop="studentSbbyzh">
                      <el-input v-model="form.studentSbbyzh" placeholder="请输入硕士毕业证书编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="最后学位码" prop="studentZhxwDm">
                      <el-input v-model="form.studentZhxwDm" placeholder="请输入最后学位码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="最后学历码" prop="studentZhxlDm">
                      <el-input v-model="form.studentZhxlDm" placeholder="请输入最后学历码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div class="info-group">
                <h4 class="group-title">其他教育信息</h4>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="考试方式" prop="ksfs">
                      <el-input v-model="form.ksfs" placeholder="请输入考试方式" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="16">
                    <el-form-item label="备注" prop="beizhu">
                      <el-input v-model="form.beizhu" type="textarea" placeholder="请输入备注" rows="2" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <!-- 补充：入伍与退役信息分组 -->
              <div class="info-group">
                <h4 class="group-title">入伍与退役信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="入伍时间" prop="studentRwsj">
                      <el-date-picker clearable
                                      v-model="form.studentRwsj"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择入伍时间"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="退役时间" prop="studentTysj">
                      <el-date-picker clearable
                                      v-model="form.studentTysj"
                                      type="date"
                                      value-format="YYYY-MM-DD"
                                      placeholder="请选择退役时间"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="批准入伍机关名称" prop="studentPzrujgmc">
                      <el-input v-model="form.studentPzrujgmc" placeholder="请输入批准入伍机关名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="批准退役机关名称" prop="studentPztyjgmc">
                      <el-input v-model="form.studentPztyjgmc" placeholder="请输入批准退役机关名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="退出现役证编号" prop="studentTcxyzbh">
                      <el-input v-model="form.studentTcxyzbh" placeholder="请输入退出现役证编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <!-- 补充：入伍前高校信息分组 -->
              <div class="info-group">
                <h4 class="group-title">入伍前高校信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="入伍前所在高校名称" prop="studentRwqszgxmc">
                      <el-input v-model="form.studentRwqszgxmc" placeholder="请输入入伍前所在高校名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="入伍前所在高校学习形式" prop="studentRwqszgxxxxs">
                      <el-input v-model="form.studentRwqszgxxxxs" placeholder="请输入学习形式（如全日制/非全日制）" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="入伍前所在高校学习专业" prop="studentRwqszgxxxzy">
                      <el-input v-model="form.studentRwqszgxxxzy" placeholder="请输入学习专业" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <!-- 补充：毕业单位与档案信息分组 -->
              <div class="info-group">
                <h4 class="group-title">毕业单位与档案信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="毕业单位" prop="studentBydw">
                      <el-input v-model="form.studentBydw" placeholder="请输入毕业单位" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="获得学士学位单位码" prop="studentBxwdywDm">
                      <el-input v-model="form.studentBxwdywDm" placeholder="请输入获得学士学位单位码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="获得学士学位单位名称" prop="studentBxwdywMc">
                      <el-input v-model="form.studentBxwdywMc" placeholder="请输入获得学士学位单位名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="获得学士学位专业代码" prop="studentBxwzyDm">
                      <el-input v-model="form.studentBxwzyDm" placeholder="请输入获得学士学位专业代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="获学士学位专业名称" prop="studentBxwzyMc">
                      <el-input v-model="form.studentBxwzyMc" placeholder="请输入获学士学位专业名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <!-- 新增：获学士学位年月 -->
                  <el-col :span="12">
                    <el-form-item label="获学士学位年月" prop="studentBxwyxny">
                      <el-date-picker clearable
                                      v-model="form.studentBxwyxny"
                                      type="month"
                                      value-format="YYYY-MM"
                                      placeholder="请选择获学士学位年月"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <!-- 新增本科相关字段 -->
                  <el-col :span="12">
                    <el-form-item label="学士学位证书编号" prop="studentBxwzh">
                      <el-input v-model="form.studentBxwzh" placeholder="请输入学士学位证书编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业单位代码" prop="studentBkbydwDm">
                      <el-input v-model="form.studentBkbydwDm" placeholder="请输入本科毕业单位代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业单位名称" prop="studentBkbydwMc">
                      <el-input v-model="form.studentBkbydwMc" placeholder="请输入本科毕业单位名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业专业代码" prop="studentBkbyzyDm">
                      <el-input v-model="form.studentBkbyzyDm" placeholder="请输入本科毕业专业代码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业专业名称" prop="studentBkbyzyMc">
                      <el-input v-model="form.studentBkbyzyMc" placeholder="请输入本科毕业专业名称" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业年月" prop="studentBkbyny">
                      <el-date-picker clearable
                                      v-model="form.studentBkbyny"
                                      type="month"
                                      value-format="YYYY-MM"
                                      placeholder="请选择本科毕业年月"
                                      style="width: 100%;"
                                      :disabled="isDetail">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科毕业证书编号" prop="studentBkbyzh">
                      <el-input v-model="form.studentBkbyzh" placeholder="请输入本科毕业证书编号" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="本科学历学习形式" prop="studentBkxxXsxs">
                      <el-input v-model="form.studentBkxxXsxs" placeholder="请输入本科学历的学习形式（如全日制、函授等）" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>


                  <el-col :span="12">
                    <el-form-item label="毕业专业" prop="studentByzy">
                      <el-input v-model="form.studentByzy" placeholder="请输入毕业专业" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="毕业专业码" prop="studentByzym">
                      <el-input v-model="form.studentByzym" placeholder="请输入毕业专业码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="档案地址" prop="studentDadz">
                      <el-input v-model="form.studentDadz" placeholder="请输入档案地址" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="档案邮政编码" prop="studentDadzyzbm">
                      <el-input v-model="form.studentDadzyzbm" placeholder="请输入档案邮政编码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <!-- 补充：定向与录取信息分组 -->
              <div class="info-group">
                <h4 class="group-title">定向与录取信息</h4>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="定向就业单位" prop="studentDxjydw">
                      <el-input v-model="form.studentDxjydw" placeholder="请输入定向就业单位" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="定向就业单位码" prop="studentDxjydwm">
                      <el-input v-model="form.studentDxjydwm" placeholder="请输入定向就业单位码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="12">
                    <el-form-item label="定向就业单位所在地码" prop="studentDxjydwSdm">
                      <el-input v-model="form.studentDxjydwSdm" placeholder="请输入定向就业单位所在地码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="录取培养单位" prop="studentLqpydw">
                      <el-input v-model="form.studentLqpydw" placeholder="请输入录取培养单位" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="录取培养单位码" prop="studentLqpydwm">
                      <el-input v-model="form.studentLqpydwm" placeholder="请输入录取培养单位码" :disabled="isDetail" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-card>
          </el-col>

          <el-col :span="8">
            <!-- 照片上传区域 -->
            <el-card shadow="hover" class="photo-card">
              <template #header>
                <div class="card-header">
                  <span>学生照片</span>
                </div>
              </template>
              <div class="photo-container">
                <el-form-item label="学生入学照片" prop="studentPhoto">
                  <ImageUpload v-model="form.studentPhoto" :limit="1" :file-type="['jpg', 'jpeg', 'png']" :disabled="isDetail" />
                </el-form-item>
              </div>
              <div class="photo-container">
                <el-form-item label="学生毕业照片" prop="studentGphoto">
                  <ImageUpload v-model="form.studentGphoto" :limit="1" :file-type="['jpg', 'jpeg', 'png']" :disabled="isDetail" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 状态信息区域 -->
            <el-card shadow="hover" class="status-card">
              <template #header>
                <div class="card-header">
                  <span>学生状态信息</span>
                </div>
              </template>

              <div class="status-group">
                <h4 class="status-title">基础状态</h4>
                <el-form-item label="报道状态" prop="studentStatus">
                  <el-select v-model="form.studentStatus" placeholder="请选择报道状态" filterable :disabled="isDetail">
                    <el-option
                        v-for="dict in bdzt"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="当前学期注册状态" prop="studentZczt">
                  <el-select v-model="form.studentZczt" placeholder="请选择注册状态" filterable :disabled="isDetail">
                    <el-option value="已注册" label="已注册"></el-option>
                    <el-option value="未注册" label="未注册"></el-option>
                    <el-option value="暂缓注册" label="暂缓注册"></el-option>
                  </el-select>
                </el-form-item>
              </div>

              <div class="status-group">
                <h4 class="status-title">学籍状态</h4>
                <el-form-item label="学籍状态" prop="studentXjzt">
                  <el-select v-model="form.studentXjzt" placeholder="请选择学籍状态" filterable :disabled="isDetail">
                    <el-option value="正常" label="正常"></el-option>
                    <el-option value="休学" label="休学"></el-option>
                    <el-option value="退学" label="退学"></el-option>
                    <el-option value="结业" label="结业"></el-option>
                    <el-option value="毕业" label="毕业"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="档案状态" prop="studentDazt">
                  <el-select v-model="form.studentDazt" placeholder="请选择档案状态" filterable :disabled="isDetail">
                    <el-option value="在库" label="在库"></el-option>
                    <el-option value="转出" label="转出"></el-option>
                    <el-option value="缺失" label="缺失"></el-option>
                  </el-select>
                </el-form-item>
              </div>

              <div class="status-group">
                <h4 class="status-title">其他状态</h4>
                <el-form-item label="确认状态" prop="studentQrzt">
                  <el-select v-model="form.studentQrzt" placeholder="请选择确认状态" filterable :disabled="isDetail">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="是否破格" prop="studentSfpg">
                  <el-select v-model="form.studentSfpg" placeholder="请选择是否破格" filterable :disabled="isDetail">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm" v-if="!isDetail">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 新增：学生导师匹配导入对话框 -->
    <el-dialog
        title="导入学生导师匹配"
        v-model="importDialogVisible"
        width="500px"
        append-to-body
    >
      <el-form ref="importForm" :model="importForm" label-width="100px">
        <el-form-item label="上传文件">
          <!-- 确保模板中的绑定正确 -->
          <el-upload
              class="upload-demo"
              ref="upload"
              action="#"
              :http-request="handleFileUpload"
              :on-change="handleFileChange"
              :before-upload="beforeFileUpload"
              :on-remove="handleFileRemove"
              :file-list="fileList"
          :auto-upload="false"
          :limit="1"
          :on-exceed="handleFileExceed"
          accept=".xlsx,.xls"
          >
          <el-button type="primary" icon="Upload">选择文件</el-button>
          <template #tip>
            <div class="el-upload__tip text-danger">
              仅支持.xlsx、.xls格式文件，且不超过2MB
            </div>
          </template>
          </el-upload>
        </el-form-item>

        <el-form-item v-if="importProgress > 0 && importProgress < 100">
          <div class="progress-container">
            <el-progress :percentage="importProgress" stroke-width="6"></el-progress>
            <div class="progress-text">
              {{ importProgress }}% 已完成
              <span v-if="importStatusMsg">{{ importStatusMsg }}</span>
            </div>
          </div>
        </el-form-item>

        <el-form-item v-if="importProgress === 100">
          <div v-if="importSuccess" class="success-message">
            <el-icon color="green"><Check /></el-icon>
            导入成功，共处理 {{ successCount }} 条数据，失败 {{ failureCount }} 条
          </div>
          <div v-else class="error-message">
            <el-icon color="red"><Close /></el-icon>
            导入失败: {{ importStatusMsg }}
          </div>
          <el-button
              v-if="failureCount > 0"
              type="text"
              @click="handleDownloadFailures"
              class="download-failures"
          >
            <el-icon><Download /></el-icon> 下载失败数据
          </el-button>
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancelImport">取消</el-button>
          <el-button
              type="primary"
              @click="submitImport"
              :disabled="fileList.length === 0 || isImporting"
          >
          <el-icon v-if="isImporting"><Loading /></el-icon>
          <span v-else>确认导入</span>
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="StudentManger">
import { getMajorByCollegeId, listMajor, getMajor } from "@/api/major/major.js";
import { listGertificatetype } from "@/api/dictionaries/gertificatetype.js";
import { debounce } from 'lodash';
import { listCollege } from "@/api/college/college.js";
import { loadAllParams } from "@/api/page.js";
import { listTeacher } from "@/api/teacher/teacher.js";
// 导入新增的API方法
import {
  delAllStudent,
  listStudentManger,
  getStudentManger,
  delStudentManger,
  addStudentManger,
  updateStudentManger,
  listByStudentZyAndNj,
  generateImportBatchNo,
  importStudentTutor,
  queryImportProgress,
  downloadFailureData,
  downloadTutorTemplate
} from "@/api/student/studentManger";
// 获取所有民族
import { listNation } from "@/api/dictionaries/nation.js";
import ImageUpload from "@/components/ImageUpload/index.vue";
import { listPoliticalstatus } from "@/api/dictionaries/politicalstatus.js";
import { pinyin } from 'pinyin-pro';
import {provinceAndCityData , regionData, codeToText} from 'element-china-area-data';
import dict from "../../../store/modules/dict.js";
import { onUnmounted } from 'vue'; // 新增：用于组件卸载时清理资源
import { selectStudentListByCollegeCode } from "@/api/student/allList.js";
const { proxy } = getCurrentInstance();
const { originpadict, grade, campus_type, semester, xuezhi, bdzt, marital_status, health_status, culture_program_type, sys_yes_no, sys_user_sex } =
    proxy.useDict('originpadict', 'grade', 'campus_type', 'semester', 'xuezhi', 'bdzt', 'marital_status', 'health_status', 'culture_program_type', 'sys_yes_no', 'sys_user_sex');
const studentMangerList = ref([]);
const open = ref(false);
const loading = ref(true); // 控制整体加载状态
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const originnationlist = ref([]);
const originpaList = ref([]);
const yxList = ref([]);
const zyList = ref([]); // 存储专业列表
const zyZlist = ref([]); // 专业总列表
const teacherList = ref([]); // 导师列表
const idcardList = ref([]); // 身份证列表
// 新增：学生导师导入相关变量
const importDialogVisible = ref(false);
const fileList = ref([]);
const currentFile = ref(null);
const importForm = reactive({});
const isImporting = ref(false);
const importProgress = ref(0);
const importStatusMsg = ref('');
const importSuccess = ref(false);
const successCount = ref(0);
const failureCount = ref(0);
const currentBatchNo = ref('');
const progressInterval = ref(null);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    studentId: null,
    studentName: null,
    studentSex: null,
    studentCnum: null,
    studentJiguan: null,
    studentBire: null,
    studentStre: null,
    studentHk: null,
    studentHkxxdz: null,
    studentYx: null,
    studentZy: null,
    studentYjfxm: null,
    studentYjfx: null,
    studentPycc: null,
    studentLb: null,
    studentNj: null,
    studentXq: null,
    studentDsbh: null,
    studentDs: null,
    studentDs2: null,
    studentBj: null,
    studentXz: null,
    studentRxjj: null,
    studentRxny: null,
    studentPyfs: null,
    studentRxf: null,
    studentStatus: null,
    studentDxjydwSdm: null,    // 定向就业单位属地码
    studentZxjh2: null,        // 专项计划2
    studentZsdwSssm: null,     // 所在单位所属部门
    studentBxwdywDm: null,     // 获学士学位单位代码
    studentBxwdywMc: null,     // 获学士学位单位名称
    studentBxwzyDm: null,      // 获学士学位专业代码
    studentBxwzyMc: null,      // 获学士学位专业名称
    studentBxwyxny: null,      // 获学士学位年月
    studentBxwzh: null,        // 学士学位证书编号
    studentBkbydwDm: null,     // 本科毕业单位代码
    studentBkbydwMc: null,     // 本科毕业单位名称
    studentBkbyzyDm: null,     // 本科毕业专业代码
    studentBkbyzyMc: null,     // 本科毕业专业名称
    studentBkbyny: null,       // 本科毕业年月
    studentBkbyzh: null,       // 本科毕业证书编号
    studentBkxxXsxs: null,     // 本科学历学习形式
    studentSxwdywDm: null,     // 获硕士学位单位代码
    studentSxwdywMc: null,     // 获硕士学位单位名称
    studentSxwzyDm: null,      // 获硕士学位专业代码
    studentSxwzyMc: null,      // 获硕士学位专业名称
    studentSxwyxny: null,      // 获硕士学位年月
    studentSxwzh: null,        // 硕士学位证书编号
    studentSxwfs: null,        // 获硕士学位方式
    studentSbbydwDm: null,     // 硕士毕业单位代码
    studentSbbydwMc: null,     // 硕士毕业单位名称
    studentSbbyzyDm: null,     // 硕士毕业专业代码
    studentSbbyzyMc: null,     // 硕士毕业专业名称
    studentSbbyny: null,       // 硕士毕业年月
    studentSbbyzh: null,       // 硕士毕业证书编号
    studentZhxwDm: null,       // 最后学位码
    studentZhxlDm: null,       // 最后学历码
    studentZxszcXh: null,      // 专项招生批次序号
    studentKslyDm: null,       // 考试来源代码
    studentKsfsDm: null,       // 考试方式代码
    studentLqlbDm: null,       // 录取类别代码
    studentXyjrDm: null        // 现役军人码
    // 新增36个字段结束
  },
  rules: {
    studentCnum: [
      { message: '请输入身份证号码', trigger: 'blur' },
      { pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '身份证格式不正确', trigger: 'blur' }
    ],
  },
  // 地区选择器选项
  options: regionData,
  optionsa: provinceAndCityData,
  // 地区选择器选中的值
  selectedOptions: [],
  // 籍贯
  selectedJiguan: [],
  selectedBire: [],
  selectedStre: [],
  selectedHk: [],
  //省市
  selectedSs:[],
  isDetail: false
});

const { queryParams, form, rules, options, optionsa,selectedOptions, selectedJiguan, selectedBire, selectedStre, selectedHk ,selectedSs,isDetail} = toRefs(data);

/** 查询学生信息管理列表（新增错误处理） */
function getList() {
  loading.value = true;
  selectStudentListByCollegeCode(queryParams.value)
      .then(response => {
        // 校验响应格式
        if (!response || !Array.isArray(response.rows) || typeof response.total !== 'number') {
          throw new Error("后端返回数据格式异常");
        }
        studentMangerList.value = response.rows;
        total.value = response.total;
        console.log("返回的总数为" + total.value);
      })
      .catch(error => {
        console.error("学生列表加载失败：", error);
        studentMangerList.value = []; // 清空异常数据
        total.value = 0;
        proxy.$modal.msgError("数据加载失败，请重试"); // 提示用户
      })
      .finally(() => {
        loading.value = false; // 无论成功失败，都结束加载
      });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    studentGphoto: null,
    studentPhoto: null,
    studentId: null,
    studentName: null,
    namePy: null,
    studentNames: null,
    studentSex: null,
    birthday: null,
    studentNation: null,
    studentPa: null,
    studentTjp: null,
    studentCtype: null,
    studentCnum: null,
    studentRe: null,
    studentRegion: null,
    studentJiguan: null,
    studentBire: null,
    studentStre: null,
    studentHk: null,
    studentHkxxdz: null,
    gangaotaiqiao: null,
    studentMarr: null,
    studentHe: null,
    studentBs: null,
    studentYhkh: null,
    studentYhkname: null,
    studentTrains: null,
    studentTraine: null,
    studentQues: null,
    studentShuji: null,
    studentSjnum: null,
    studentFdy: null,
    studentFdynum: null,
    studentSy: null,
    studentYx: null,
    studentZy: null,
    studentYjfxm: null,
    studentYjfx: null,
    studentPycc: null,
    studentLb: null,
    studentNj: null,
    studentXq: null,
    studentDs: null,
    studentDs2: null,
    studentBj: null,
    studentXz: null,
    studentRxjj: null,
    studentRxny: null,
    studentYjby: null,
    studentSjby: null,
    studentMl: null,
    studentPyfs: null,
    studentRxf: null,
    studentZxjh: null,
    studentJdfs: null,
    studentXxfs: null,
    studentJxxz: null,
    studentSfbxtm: null,
    studentSfbxdx: null,
    studentSflkxk: null,
    studentSfzzs: null,
    studentSflxs: null,
    studentTsxsx: null,
    studentXsfl: null,
    studentXwlx: null,
    studentXw: null,
    studentZxbs: null,
    studentZczt: null,
    studentXjzt: null,
    studentDazt: null,
    studentSfpg: null,
    studentDaqx: null,
    studentQrzt: null,
    studentBydw: null,
    studentByzy: null,
    studentByzym: null,
    studentDadz: null,
    studentDadzyzbm: null,
    studentDbsj: null,
    studentByzh: null,
    studentXwzh: null,
    studentJcxx: null,
    ksfs: null,
    beizhu: null,
    studentDxjydw: null,
    studentDxjydwm: null,
    studentLqpydw: null,
    studentLqpydwm: null,
    studentSjh: null,
    studentRwsj: null,
    studentTysj: null,
    studentPzrujgmc: null,
    studentPztyjgmc: null,
    studentTcxyzbh: null,
    studentRwqszgxmc: null,
    studentRwqszgxxxxs: null,
    studentRwqszgxxxzy: null,
    studentStatus: null,
    // 新增36个字段开始（与data中form的字段完全一致）
    studentDxjydwSdm: null,
    studentZxjh2: null,
    studentZsdwSssm: null,
    studentBxwdywDm: null,
    studentBxwdywMc: null,
    studentBxwzyDm: null,
    studentBxwzyMc: null,
    studentBxwyxny: null,
    studentBxwzh: null,
    studentBkbydwDm: null,
    studentBkbydwMc: null,
    studentBkbyzyDm: null,
    studentBkbyzyMc: null,
    studentBkbyny: null,
    studentBkbyzh: null,
    studentBkxxXsxs: null,
    studentSxwdywDm: null,
    studentSxwdywMc: null,
    studentSxwzyDm: null,
    studentSxwzyMc: null,
    studentSxwyxny: null,
    studentSxwzh: null,
    studentSxwfs: null,
    studentSbbydwDm: null,
    studentSbbydwMc: null,
    studentSbbyzyDm: null,
    studentSbbyzyMc: null,
    studentSbbyny: null,
    studentSbbyzh: null,
    studentZhxwDm: null,
    studentZhxlDm: null,
    studentZxszcXh: null,
    studentKslyDm: null,
    studentKsfsDm: null,
    studentLqlbDm: null,
    studentXyjrDm: null
    // 新增36个字段结束
  };
  proxy.resetForm("studentMangerRef");
  selectedOptions.value = [];
  selectedJiguan.value = [];
  selectedBire.value = [];
  selectedStre.value = [];
  selectedHk.value = [];
  selectedSs.value = [];
}

/** 搜索按钮操作 */
function handleQuery() {
  console.log(queryParams.value);
  queryParams.value.pageNum = 1;
  getList();
}

// 院系变更时触发
function handleCollegeChange(collegeId) {
  console.log(collegeId);
  if (!collegeId) return; // 未选择时不执行
  // 调用API查询该院系下的专业
  getMajorByCollegeId(collegeId).then(response => {
    zyList.value = response.rows; // 假设返回格式为 { rows: [...] }
    console.log(zyList.value)
    // 可选：自动清空之前的专业选择（如果需要）
    queryParams.value.studentZy = null;
    form.value.studentZy = null;
  });
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  isDetail.value = false;
  open.value = true;
  title.value = "添加学生信息管理";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  isDetail.value = false;
  const _id = row.id || ids.value;
  // 先加载专业列表，再加载学生数据
  getMajorByCollegeId(row.studentYx).then(response => {
    zyList.value = response.rows;
    getStudentManger(_id).then(response => {
      form.value = response.data;
      selectedOptions.value = form.value.studentRegion;
      selectedJiguan.value = form.value.studentJiguan;
      selectedBire.value = form.value.studentBire;
      selectedStre.value = form.value.studentStre;
      selectedHk.value = form.value.studentHk;
      selectedSs.value = form.value.studentZsdwSssm;
      //form.value.studentZy = zyList.value.find(item => item.majorCode === form.value.studentZy)?.majorName || "暂无数据";
      open.value = true;
      title.value = "修改学生信息管理";
    });
  });
}

/** 查看详情操作 */
function handleDetail(row) {
  reset();
  isDetail.value = true;
  const _id = row.id || ids.value;
  // 先加载专业列表，再加载学生数据
  getMajorByCollegeId(row.studentYx).then(response => {
    zyList.value = response.rows;
    getStudentManger(_id).then(response => {
      form.value = response.data;
      selectedOptions.value = form.value.studentRegion;
      selectedJiguan.value = form.value.studentJiguan;
      selectedBire.value = form.value.studentBire;
      selectedStre.value = form.value.studentStre;
      selectedHk.value = form.value.studentHk;
      selectedSs.value = form.value.studentZsdwSssm;
      //form.value.studentZy = zyList.value.find(item => item.majorCode === form.value.studentZy)?.majorName || "专业字典无此专业";
      open.value = true;
      title.value = "学生信息详情";
    });
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["studentMangerRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateStudentManger(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addStudentManger(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除学生信息管理编号为"' + _ids + '"的数据项？').then(function () {
    return delStudentManger(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('student/studentManger/export', {
    ...queryParams.value
  }, `studentManger_${new Date().getTime()}.xlsx`)
}

/** 获取民族列表（返回Promise便于异步控制） */
function getNationalities() {
  return new Promise((resolve, reject) => {
    listNation(loadAllParams).then(response => {
      originnationlist.value = response.rows;
      resolve();
    }).catch(error => {
      console.error("民族列表加载失败：", error);
      reject(error); // 传递错误，中断初始化
    });
  });
}

/** 获取政治面貌列表（返回Promise便于异步控制） */
function getPoliticalAffiliations() {
  return new Promise((resolve, reject) => {
    listPoliticalstatus(loadAllParams).then(response => {
      originpaList.value = response.rows;
      resolve();
    }).catch(error => {
      console.error("政治面貌列表加载失败：", error);
      reject(error);
    });
  });
}

/** 获取学院列表（返回Promise便于异步控制） */
function getColleges() {
  return new Promise((resolve, reject) => {
    listCollege(loadAllParams).then(response => {
      yxList.value = response.rows;
      console.log(yxList.value);
      resolve();
    }).catch(error => {
      console.error("学院列表加载失败：", error);
      reject(error);
    });
  });
}

/** 获取专业列表（返回Promise便于异步控制） */
function getlistMajor() {
  return new Promise((resolve, reject) => {
    listMajor(loadAllParams).then(response => {
      zyZlist.value = response.rows;
      resolve();
    }).catch(error => {
      console.error("专业列表加载失败：", error);
      reject(error);
    });
  });
}

/** 获取证件类型列表（返回Promise便于异步控制） */
function getIdCard() {
  return new Promise((resolve, reject) => {
    listGertificatetype(loadAllParams).then(response => {
      idcardList.value = response.rows;
      resolve();
    }).catch(error => {
      console.error("证件类型列表加载失败：", error);
      reject(error);
    });
  });
}

/** 获取教师列表（返回Promise便于异步控制） */
function getTeacher() {
  return new Promise((resolve, reject) => {
    listTeacher(loadAllParams).then(response => {
      console.log("教师列表数据：", response.rows);
      teacherList.value = response.rows;
      // 格式化教师名称（工号+姓名）
      teacherList.value.forEach(item => {
        item.name = `${item.teacherCode} ${item.name}`;
      });
      resolve();
    }).catch(error => {
      console.error("教师列表加载失败：", error);
      reject(error);
    });
  });
}

// 地区选择器回调
function handleChange() {
  form.value.studentRegion = selectedOptions.value[2];
}
function handleChangeJiguan() {
  form.value.studentJiguan = selectedJiguan.value[2];
}
function handleChangeBire() {
  form.value.studentBire = selectedBire.value[2];
}
function handleChangeStre() {
  form.value.studentStre = selectedStre.value[2];
}
function handleChangeHk() {
  form.value.studentHk = selectedHk.value[2];
}
function handleChangeSs() {
  form.value.studentZsdwSssm = selectedSs.value[1];
  console.log(form.value.studentZsdwSssm);
}
// 依据身份证号获取性别
function getSex() {
  if (form.value.studentCnum?.length >= 17) {
    const sex = form.value.studentCnum.at(16) % 2 === 0 ? '女' : '男';
    if (form.value.studentSex !== sex) {
      form.value.studentSex = sex;
      proxy.$modal.msgSuccess(`已根据身份证修改学生性别为: ${sex}`);
    }
  }
}

// 姓名拼音生成（防抖处理）
const debouncedGetNamePy = debounce(function () {
  if (form.value.studentName) {
    form.value.namePy = pinyin(form.value.studentName, {
      style: pinyin.STYLE_FIRST_LETTER,
      toneType: "none",
      type: "string"
    });
  }
}, 500);
function getNamePy() {
  debouncedGetNamePy();
}

// 删除所有学生信息
function handleDeleteAll() {
  proxy.$modal.confirm('是否确认删除所有学生信息管理数据项？').then(function () {
    return delAllStudent();
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

// 核心：初始化函数（异步顺序执行）
async function init() {
  loading.value = true; // 初始化期间显示整体加载状态
  try {
    // 1. 先加载所有依赖的字典数据（并行执行，提升速度）
    await Promise.all([
      getNationalities(),
      getPoliticalAffiliations(),
      getColleges(),
      getlistMajor(),
      getTeacher(),
      getIdCard()
    ]);
    // 2. 依赖数据加载完成后，加载学生列表
    await getList();
  } catch (error) {
    console.error("初始化失败：", error);
    proxy.$modal.msgError("页面初始化失败，请刷新重试");
  } finally {
    loading.value = false; // 无论成功失败，都结束初始化加载
  }
}
// 新增：处理导入对话框打开
function handleImportTutor() {
  resetImportForm();
  importDialogVisible.value = true;
}

// 新增：重置导入表单
function resetImportForm() {
  fileList.value = [];
  currentFile.value = null;
  isImporting.value = false;
  importProgress.value = 0;
  importStatusMsg.value = '';
  importSuccess.value = false;
  successCount.value = 0;
  failureCount.value = 0;
  currentBatchNo.value = '';
  if (progressInterval.value) {
    clearInterval(progressInterval.value);
    progressInterval.value = null;
  }
}

// 新增：取消导入
function cancelImport() {
  resetImportForm();
  importDialogVisible.value = false;
}

// 1. 修改 fileList 定义（从 ref 改为 reactive）
// 替代原 const fileList = ref([]);

// 2. 修复 handleFileChange 函数（用数组方法更新，保留响应式）
// 修复：应该直接操作 ref 的 value
function handleFileChange(file, uploadedFileList) {
  fileList.value = [{
    ...file,
    status: 'ready'
  }];
  currentFile.value = file.raw;
}

// 3. 修复 handleFileRemove 函数（同样用 splice 清空）
// 修复：应该操作 ref 的 value
function handleFileRemove() {
  fileList.value = [];
  currentFile.value = null;
}

// 改进文件上传前验证
function beforeFileUpload(file) {
  // 更详细的文件类型检查
  const fileExt = file.name.split('.').pop().toLowerCase();
  const isExcel = ['xlsx', 'xls'].includes(fileExt);

  // 更详细的文件大小检查
  const fileSizeMB = file.size / 1024 / 1024;
  const isLt2M = fileSizeMB < 2;

  console.log(`文件验证 - 名称: ${file.name}, 类型: ${file.type}, 扩展名: ${fileExt}, 大小: ${fileSizeMB.toFixed(2)}MB`);

  if (!isExcel) {
    proxy.$modal.msgError('上传文件只能是.xlsx或.xls格式!');
    return false;
  }
  if (!isLt2M) {
    proxy.$modal.msgError(`上传文件大小不能超过2MB! 当前文件大小: ${fileSizeMB.toFixed(2)}MB`);
    return false;
  }

  // 检查文件是否为空
  if (file.size === 0) {
    proxy.$modal.msgError('不能上传空文件!');
    return false;
  }

  return true;
}

// 新增：自定义文件上传处理（实际在submitImport中处理）
function handleFileUpload() {
  // 空实现，因为我们在submitImport中手动处理上传
}

// 新增：提交导入
// 修复：提交导入（核心逻辑）
// 改进提交导入函数
async function submitImport() {
  if (!currentFile.value || fileList.value.length === 0) {
    proxy.$modal.msgWarning('请先选择要导入的文件');
    return;
  }

  try {
    isImporting.value = true;
    importStatusMsg.value = '正在准备导入...';

    // 生成导入批次号
    const batchRes = await generateImportBatchNo();
    currentBatchNo.value = batchRes.data;
    if (!currentBatchNo.value) {
      throw new Error('获取导入批次号失败，请重试');
    }

    // 构建FormData - 增加错误处理
    const formData = new FormData();
    try {
      formData.append('file', currentFile.value);
      formData.append('batchNo', currentBatchNo.value);
      // 打印FormData内容用于调试
      console.log('FormData内容:');
      formData.forEach((value, key) => {
        console.log(`${key}: ${key === 'file' ? value.name : value}`);
      });
    } catch (formError) {
      throw new Error(`构建上传数据失败: ${formError.message}`);
    }

    // 调用上传接口 - 增加超时处理
    const uploadPromise = importStudentTutor(formData);
    // 设置5分钟超时
    const timeoutPromise = new Promise((_, reject) =>
        setTimeout(() => reject(new Error('上传超时，请检查网络或文件大小')), 300000)
    );

    //  raced between upload and timeout
    await Promise.race([uploadPromise, timeoutPromise]);

    // 开始查询导入进度
    importStatusMsg.value = '正在导入数据...';
    await checkImportProgress();
    // 动态调整查询频率，开始频繁些，后来降低频率
    let intervalTime = 1000; // 开始1秒一次
    progressInterval.value = setInterval(() => {
      checkImportProgress();
      // 20秒后变为3秒一次，40秒后变为5秒一次
      if (importProgress.value > 50 && intervalTime < 3000) {
        intervalTime = 3000;
        clearInterval(progressInterval.value);
        progressInterval.value = setInterval(checkImportProgress, intervalTime);
      } else if (importProgress.value > 80 && intervalTime < 5000) {
        intervalTime = 5000;
        clearInterval(progressInterval.value);
        progressInterval.value = setInterval(checkImportProgress, intervalTime);
      }
    }, intervalTime);

  } catch (error) {
    console.error('导入失败详情:', error);
    // 更详细的错误信息
    let errorMsg = '导入失败，请重试';
    if (error.response) {
      // 服务器返回错误
      errorMsg = `服务器错误: ${error.response.data?.msg || '未知错误'}`;
      console.error('服务器响应错误:', error.response);
    } else if (error.request) {
      // 无响应
      errorMsg = '未收到服务器响应，请检查网络连接';
    } else {
      // 其他错误
      errorMsg = error.message;
    }
    importStatusMsg.value = errorMsg;
    isImporting.value = false;
    // 显示错误详情对话框
    proxy.$modal.error({
      title: '导入失败',
      content: errorMsg,
      showCancelButton: false
    });
  }
}

// 改进检查导入进度函数
async function checkImportProgress() {
  if (!currentBatchNo.value) return;

  try {
    const progressRes = await queryImportProgress(currentBatchNo.value);
    const progressData = progressRes.data;

    if (!progressData) {
      throw new Error('进度数据格式不正确');
    }

    // 使用后端实际返回的字段，而不是不存在的percentage字段
    importProgress.value = progressData.progress || 0;
    importStatusMsg.value = progressData.message || `正在处理...(${importProgress.value}%)`;

    // 如果导入完成（根据后端实际返回的状态和进度判断）
    if (progressData.progress >= 100 || progressData.status === '完成') {
      clearInterval(progressInterval.value);
      progressInterval.value = null;
      isImporting.value = false;

      // 根据后端实际返回的字段设置成功状态
      importSuccess.value = progressData.failCount === 0;
      successCount.value = progressData.successCount || 0;
      failureCount.value = progressData.failCount || 0;

      if (importSuccess.value) {
        importStatusMsg.value = `导入成功，共处理 ${successCount.value} 条，失败 ${failureCount.value} 条`;
        getList(); // 刷新学生列表
      } else {
        importStatusMsg.value = progressData.errorMsg || '导入过程中发生错误';
      }
    }
  } catch (error) {
    console.error('查询进度失败:', error);
    importStatusMsg.value = `查询进度失败: ${error.message}`;
    // 3次失败后停止查询，但保留界面状态
    if (window.progressFailureCount) {
      window.progressFailureCount++;
      if (window.progressFailureCount >= 3) {
        clearInterval(progressInterval.value);
        progressInterval.value = null;
        isImporting.value = false;
        importStatusMsg.value = '多次查询进度失败，请手动刷新查看结果';
      }
    } else {
      window.progressFailureCount = 1;
    }
  }
}


// 新增：文件超出限制时提示
function handleFileExceed(files, fileList) {
  proxy.$modal.msgWarning(`最多只能选择1个文件，已自动过滤多余文件`);
}
// 新增：下载失败数据
function handleDownloadFailures() {
  if (!currentBatchNo.value) {
    proxy.$modal.msgWarning('没有批次号，无法下载');
    return;
  }

  downloadFailureData(currentBatchNo.value).then(response => {
    const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = `导师匹配导入失败数据_${currentBatchNo.value}.xlsx`;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    document.body.removeChild(a);
  }).catch(error => {
    console.error('下载失败数据出错:', error);
    proxy.$modal.msgError('下载失败，请重试');
  });
}

//新增：下载导入模板
// function handleDownloadTemplate() {
//   downloadTutorTemplate().then(response => {
//     const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
//     const url = window.URL.createObjectURL(blob);
//     const a = document.createElement('a');
//     a.href = url;
//     a.download = '学生导师匹配导入模板.xlsx';
//     document.body.appendChild(a);
//     a.click();
//     window.URL.revokeObjectURL(url);
//     document.body.removeChild(a);
//   }).catch(error => {
//     console.error('下载模板出错:', error);
//     proxy.$modal.msgError('下载模板失败，请重试');
//   });
// }
function handleDownloadTemplate() {
  // 原错误：this.download → 修正为 proxy.download（RuoYi 框架方法挂载在实例上）
  proxy.download('/student/studentManger/downloadTutorTemplate', {},
      `学生导师指定导入模板_${new Date().getTime()}.xlsx`);
}

// 组件卸载时清理资源（防止内存泄漏）
// 组件卸载时清理资源
onUnmounted(() => {
  debouncedGetNamePy.cancel();
  if (progressInterval.value) {
    clearInterval(progressInterval.value);
  }
});

// 启动初始化
init();
</script>
<style scoped>
.student-detail-dialog {
  font-family: 'Microsoft YaHei', sans-serif;
}

.info-card {
  margin-bottom: 20px;
  border-radius: 8px;
}

.photo-card, .status-card {
  margin-bottom: 20px;
  border-radius: 8px;
}

.card-header {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  display: flex;
  align-items: center;
  padding: 10px 15px;
}

.card-header::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 16px;
  background-color: #409EFF;
  margin-right: 8px;
  border-radius: 2px;
}

.info-group {
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f9fafc;
  border-radius: 6px;
  border-left: 4px solid #409EFF;
}

.group-title {
  margin: 0 0 15px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #ebeef5;
  color: #409EFF;
  font-size: 14px;
  font-weight: 500;
}

/* 状态信息样式优化 */
.status-card {
  background-color: #f9fafc;
  border: 1px solid #ebeef5;
}

.status-group {
  margin-bottom: 15px;
  padding: 10px 0;
  border-bottom: 1px dashed #ebeef5;
}

.status-group:last-child {
  border-bottom: none;
}

.status-title {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: #606266;
  font-weight: 500;
  padding-left: 5px;
}

/* 照片上传区域样式 */
.photo-container {
  margin-bottom: 20px;
  text-align: center;
  padding: 10px;
  background-color: #f9fafc;
  border-radius: 6px;
}

.photo-container .el-form-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.photo-container .el-form-item__label {
  margin-bottom: 10px;
  font-weight: 500;
  color: #606266;
  color: #606266;
}

.dialog-footer {
  text-align: center;
  padding-top: 20px;
}

/* 表单元素间距优化 */
.el-form-item {
  margin-bottom: 15px;
}

/* 表格操作列样式优化 */
::v-deep .el-table .cell {
  white-space: nowrap;
}

::v-deep .el-select {
  width: 100%;
}
/* 新增：导入对话框样式 */
.progress-container {
  margin-top: 10px;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 14px;
}

.success-message {
  color: #67C23A;
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.error-message {
  color: #F56C6C;
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.download-failures {
  margin-top: 10px;
  color: #409EFF;
}

::v-deep .el-upload__tip {
  margin-top: 5px;
  font-size: 12px;
}
</style>
